<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/jquery-2.1.1.min.js"></script>
    <script src="/js/my97/WdatePicker.js"></script>
    <link rel="stylesheet" href="/js/uploadify/uploadify.css" />
    <script src="/js/uploadify/jquery.uploadify.min.js"></script>
    <link rel="stylesheet" href="/js/kindeditor-4.1.10/themes/default/default.css" />
    <script src="/js/kindeditor-4.1.10/kindeditor-all.js"></script>
    <link rel="stylesheet"href="/js/easyui1.5/themes/default/easyui.css"type="text/css"></link>
    <link rel="stylesheet"href="/js/easyui1.5/themes/icon.css"type="text/css"></link>
    <script type="text/javascript" src="/js/easyui1.5/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/js/easyui1.5/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>
<a id="btn_add" onclick="addData()" href="javascript:void(0)"class="easyui-linkbutton" data-options="iconCls:'icon-remove'">增加</a>
<table id="dg" fit="true"></table>

<!-- 弹框增加start -->
<div id="dialog_add" class="easyui-dialog" title="My Dialog"
     style="width:800px;height:400px;"
     data-options="iconCls:'icon-save',resizable:true,modal:true,
				buttons:[{
					text:'保存',
					iconCls:'icon-no',
					handler:function(){
						submitData()//调用另一个方法
					}
				},{
					text:'关闭',
					iconCls:'icon-more',
					handler:function(){
						closedSubmitData()
						 $('#dialog_add').dialog('close');
					}
				}]">
    <form id="add_form">
        <input type="hidden" name="id">
        敏感词:<input name="text" class="easyui-textbox" data-options="iconCls:'icon-man'" style="width:200px"><br>
    </form>
</div>
</body>
<script type="text/javascript" th:inline="none">
    $(function(){
        getHaa();

        normal2ajax();
        $('#dialog_add').dialog('close');

    })

    function  getHaa(){
        $("#dg").datagrid({
            url:'/ping/getStv',
            pagination:true,
            toolbar:"#gongneng",
            pageList:[5,8,10],
            pageSize:8,
            checkOnSelect:false,
            columns:[[
                {field:'xxx',title:'xx',width:100,checkbox:true},
                {field:'id',title:'ID',width:100},
                {field:'text',title:'敏感词',width:100},
                {field:'xsxs',title:'操作',width:100,
                    formatter:function(value,row,index){
                        var content = " <a href='JavaScript:delRole("+row.id+")' >删除</a> ";
                        content += " <a href='JavaScript:updaRole("+row.id+")' >修改</a> ";
                        return content;
                    }
                }
            ]]

        })
    }

    function delRole(id){
        $.messager.confirm('确认','您确认想要删除这条记录吗？',function(r){
            if (r){//点击确认
                deleteItems(id);
            }
        });
    }
    function setEvent(){
        $("#btn_delete").linkbutton({
            onClick:function(){
                var rows=$("#dg").datagrid("getChecked");
                var ids="";
                $.each(rows,function(index,obj){
                    ids+=ids==''?obj.id:","+obj.id;
                });
                deleteItems(ids);
            }
        });
    }
    function deleteItems(ids){
        $.ajax({
            url:"/ping/delStv",
            type:"POST",
            data:{id:ids},
            success:function(pageUtil){
                if(pageUtil.length>20){

                    window.location="/view/reject"
                }else{
                    /* deleteItems start */
                    $.messager.show({
                        title:'删除',
                        msg:'删除成功',
                        timeout:2000,
                        showType:'slide'
                    });
                    getHaa();
                }

            },
            error:function(pageUtil){
                if(pageUtil==0){
                    alert("代码错误");
                }else{
                    alert("删除失败");
                }
            }
        });
    }
    /* 修改start */
    function updaRole(id){
        $.ajax({
            url:"/ping/upadStv",
            type:"POST",
            data:{id:id},
            success:function(result){
                $("#dialog_add").dialog("open");
                $('#add_form').form('load',result);
            },
            error:function(){
                alert("失败了");
            }
        });
    }

    //=====新增
    function normal2ajax(){
        $('#add_form').form({
            url:'/ping/addStv',
            onSubmit: function(){
            },
            success:function(data){
                if(data.length>20){

                    window.location="/view/reject"
                }
                if(data==1){
                    alert("不能添加重复的编号");
                }else{
                    closedSubmitData();
                    $("#dialog_add").dialog("close");
                    $('#dg').datagrid('reload');
                }
            }
        });
    }
    function submitData(){//进行提交表单
        $("#add_form").form('submit');
        $("#dialog_add").dialog("close");
    }
    function addData(){
        $("#dialog_add").dialog("open");
        closedSubmitData();
    }
    function closedSubmitData(){
        $('#dialog_add').form("clear");
    }


    </script>
</html>